﻿@using System.Data;
@using System.Web;
@using DTcms.Web.MVC.Areas.Web.Controllers;
@using DTcms.Web.MVC.UI.Controllers;
@using DTcms.Model;
@{
   Layout = "~/Areas/Web/Views/" + ViewBag.TemplateSkin + "/web/Shared/_Layout.cshtml";
   DTcms.Model.channel_site site = ViewData["site"] as DTcms.Model.channel_site;
   DTcms.Model.siteconfig config = ViewData["config"] as DTcms.Model.siteconfig;
   BaseController bc = ViewBag.BasePage as BaseController;
   UserController c = ViewBag.This as UserController;
   DTcms.Model.users m = c.userModel;
   ViewBag.Title = "站内短信息 - " + site.name;
   string action = ViewBag.Action as string;
   DataTable list = null;
   int totalcount = 0;
   int page = int.Parse(ViewBag.Page as string);
   string pagelist = string.Empty;
   string user_avatar = string.Empty;
}
@section HeaderContent{
@switch(action){
   case "add":
      <link rel="stylesheet" type="text/css" href="@(config.webpath)Content/validate.css" />
      <script type="text/javascript" src="@(config.webpath)scripts/jquery/jquery.form.min.js"></script>
      <script type="text/javascript" src="@(config.webpath)scripts/Validform_v5.3.2_min.js"></script>
      <script type="text/javascript">
         $(function () {
            //初始化表单
            AjaxInitForm('#addForm', '#btnSubmit', 1, '#turl');
         });
	  </script>      
      break;
}

<script>
   function ExecPostBack(checkValue) {
      if (arguments.length == 1) {
         ExecDelete('@(config.webpath)tools/submit_ajax.ashx?action=user_message_delete', checkValue, '#turl');
      } else {
         var valueArr = '';
         $("input[name='checkId']:checked").each(function (i) {
            valueArr += $(this).val();
            if (i < $("input[name='checkId']:checked").length - 1) {
               valueArr += ","
            }
         });
         ExecDelete('@(config.webpath)tools/submit_ajax.ashx?action=user_message_delete', valueArr, '#turl');
      }
   }
</script>
}
<div class="section clearfix">
  <div class="line30"></div>

  <div class="info-wrap">
    <!--左侧导航-->
    @RenderPage("~/Areas/Web/Views/" + ViewBag.TemplateSkin + "/web/Shared/partial_ucenter_nav.cshtml")
    <!--/左侧导航-->
    
    <!--右侧内容-->
    <div class="home-box">
      @if(action=="system"){
      <!--系统消息-->
      <div class="u-tab-head">
        <p>
          <a class="selected" href="@bc.linkurl("usermessage","system")">系统消息</a>
          <a href="@bc.linkurl("usermessage","accept")">收件箱</a>
          <a href="@bc.linkurl("usermessage","send")">发件箱</a>
        </p>
        <span>
          <a class="add" href="@bc.linkurl("usermessage","add")">+ 写新消息</a>
        </span>
      </div>
      <div class="u-tab-content">
        <div class="title-div">
          <strong>系统消息</strong>
        </div>
        <table width="100%" border="0" cellspacing="0" cellpadding="0" class="mtable">
        @{
          list = bc.get_user_message_list(10, page, "accept_user_name='" + m.user_name + "' and type=1", out totalcount);<!--取得一个DataTable-->
          pagelist = bc.get_page_link(10, page, totalcount, "usermessage", action, "__id__"); <!--取得分页页码列表-->
          foreach(DataRow dr in list.Rows){
            <tr>
              <td width="20" align="center"><input name="checkId" class="checkall" type="checkbox" value="@dr["id"]" ></td>
              <td><a href="@bc.linkurl("usermessage_show",dr["id"])">@dr["title"]</a></td>
              <td width="30" align="center">
                @(dr["is_read"].ToString() == "1" ? "已读" : "未读")
              </td>
              <td width="150">@dr["post_time"]</td>
              <td width="38"><a onclick="ExecPostBack('@dr["id"]');" href="javascript:;">删除</a></td>
            </tr>
          }
          }
          @if(list.Rows.Count==0){
            <tr><td align="center">暂无记录...</td></tr>
          }
        </table>
        <div class="page-foot">
          <div class="flickr right">@Html.Raw(pagelist)</div><!--放置页码列表-->
          <div class="page-btns">
            <a onclick="checkAll(this);" href="javascript:;">全选</a>
            <span class="pipe">|</span>
            <a onclick="ExecPostBack();" href="javascript:;">删除</a>
          </div>
        </div>
      </div>
      <input id="turl" type="hidden" value="@bc.linkurl("usermessage","system")" /><!--存在跳转的URL值-->
      <!--/系统消息-->
    
      }else if(action=="accept"){
      <!--收件箱-->
      <div class="u-tab-head">
        <p>
          <a href="@bc.linkurl("usermessage","system")">系统消息</a>
          <a class="selected" href="@bc.linkurl("usermessage","accept")">收件箱</a>
          <a href="@bc.linkurl("usermessage","send")">发件箱</a>
        </p>
        <span>
          <a class="add" href="@bc.linkurl("usermessage","add")">+ 写新消息</a>
        </span>
      </div>
      <div class="u-tab-content">
        <div class="title-div">
          <strong>收件箱</strong>
        </div>
        <table width="100%" border="0" cellspacing="0" cellpadding="0" class="mtable">
        @{
          list = bc.get_user_message_list(10, page, "accept_user_name='"+ m.user_name + "' and type=2", out totalcount); <!--取得一个DataTable-->
          pagelist = bc.get_page_link(10, page, totalcount, "usermessage", action, "__id__"); <!--取得分页页码列表-->
          foreach(DataRow dr in list.Rows){
            <tr>
              <td width="20" align="center"><input name="checkId" class="checkall" type="checkbox" value="@dr["id"]" ></td>
              <td width="48">
                @user_avatar = bc.get_user_avatar(dr["post_user_name"]);
                @if(user_avatar==""){
                <img src="~/template/@ViewBag.Templateskin/web/images/user-avatar.png" width="48" height="48" />
                }else{
                <img src="@user_avatar" width="48" height="48" alt="@dr["post_user_name"]" />
                }
              </td>
              <td><strong>@dr["post_user_name"]</strong><br /><a href="@bc.linkurl("usermessage_show",dr["id"])%>">@dr["title"]</a></td>
              <td width="30" align="center">
                @(dr["is_read"].ToString() == "1" ? "已读" : "未读")
              </td>
              <td width="150">@dr["post_time"]</td>
              <td width="30"><a onclick="ExecPostBack('@dr["id"]');" href="javascript:;">删除</a></td>
            </tr>
          }
          }
          @if(list.Rows.Count==0){
            <tr><td align="center">暂无记录...</td></tr>
          }
        </table>
        <div class="page-foot">
          <div class="flickr right">@Html.Raw(pagelist)</div><!--放置页码列表-->
          <div class="page-btns">
            <a onclick="checkAll(this);" href="javascript:;">全选</a>
            <span class="pipe">|</span>
            <a onclick="ExecPostBack();" href="javascript:;">删除</a>
          </div>
        </div>
      </div>
      <input id="turl" type="hidden" value="@bc.linkurl("usermessage","accept")" />
      <!--/收件箱-->
      
      }else if(action=="send"){
      <!--发件箱-->
      <div class="u-tab-head">
        <p>
          <a href="@bc.linkurl("usermessage","system")">系统消息</a>
          <a href="@bc.linkurl("usermessage","accept")">收件箱</a>
          <a class="selected" href="@bc.linkurl("usermessage","send")">发件箱</a>
        </p>
        <span>
          <a class="add" href="@bc.linkurl("usermessage","add")">+ 写新消息</a>
        </span>
      </div>
      <div class="u-tab-content">
        <div class="title-div">
          <strong>发件箱</strong>
        </div>
        <table width="100%" border="0" cellspacing="0" cellpadding="0" class="mtable">
      @{
         list = bc.get_user_message_list(10, page, "post_user_name='"+@m.user_name+"' and type=3", out totalcount); <!--取得一个DataTable-->
         pagelist = bc.get_page_link(10, page, totalcount, "usermessage", action, "__id__"); <!--取得分页页码列表-->
         foreach(DataRow dr in list.Rows){
            <tr>
              <td width="20" align="center"><input name="checkId" class="checkall" type="checkbox" value="@dr["id"]" ></td>
              <td width="48">
                @user_avatar = bc.get_user_avatar(dr["accept_user_name"]);
                @if(user_avatar==""){
                <img src="~/template/@ViewBag.Templateskin/web/images/user-avatar.png" width="48" height="48" />
                }else{
                <img src="@user_avatar" width="48" height="48" alt="@dr["accept_user_name"]" />
                }
              </td>
              <td><strong>@dr["accept_user_name"]</strong><br /><a href="@bc.linkurl("usermessage_show",@dr["id"])%>">@dr["title"]</a></td>
              <td width="150">@dr["post_time"]</td>
              <td width="30"><a onclick="ExecPostBack('@dr["id"]');" href="javascript:;">删除</a></td>
            </tr>
          }
          if(list.Rows.Count==0){
            <tr><td align="center">暂无记录...</td></tr>
          }
        }
        </table>
        <div class="page-foot">
          <div class="flickr right">@pagelist</div><!--放置页码列表-->
          <div class="page-btns">
            <a onclick="checkAll(this);" href="javascript:;">全选</a>
            <span class="pipe">|</span>
            <a onclick="ExecPostBack();" href="javascript:;">删除</a>
          </div>
        </div>
      </div>
      <input id="turl" type="hidden" value="@bc.linkurl("usermessage","send")" />
      <!--/发件箱-->
      
      }else if(action=="add"){
      <!--发布短信息-->

      <div class="u-tab-head">
        <p>
          <a href="@bc.linkurl("usermessage","system")">系统消息</a>
          <a href="@bc.linkurl("usermessage","accept")">收件箱</a>
          <a href="@bc.linkurl("usermessage","send")">发件箱</a>
        </p>
      </div>
      <div class="u-tab-content">
        <div class="title-div">
          <strong>发短消息</strong>
        </div>
        <form id="addForm" name="addForm" url="@(config.webpath)tools/submit_ajax.ashx?action=user_message_add">
          <div class="form-box">
            <dl>
              <dt>收件人：</dt>
              <dd>
                <input name="txtUserName" id="txtUserName" type="text" class="input txt" datatype="s1-50"  nullmsg="请填写收件人用户名" sucmsg=" " />
              </dd>
            </dl>
            <dl>
              <dt>标题：</dt>
              <dd><input name="txtTitle" id="txtTitle" type="text" class="input txt" datatype="*1-50" sucmsg=" " /></dd>
            </dl>
            <dl>
              <dt>内容：</dt>
              <dd>
                <textarea name="txtContent" class="input" style="width:300px;height:80px;" datatype="*" sucmsg=" "></textarea>
              </dd>
            </dl>
            <dl>
              <dt></dt>
              <dd>
                <label><input name="sendSave" type="checkbox" value="true" checked="checked" /> 保存到发件箱</label>
              </dd>
            </dl>
            <dl>
              <dt></dt>
              <dd>
                <input id="txtCode" name="txtCode" class="input small" type="text" datatype="*" sucmsg=" " style="ime-mode:disabled;text-transform:uppercase;">
                <a id="verifyCode" href="javascript:;" onclick="ToggleCode(this, '@(config.webpath)tools/verify_code.ashx');return false;"><img src="@(config.webpath)tools/verify_code.ashx" width="80" height="22" style="vertical-align:middle;" /> 看不清楚？</a>
              </dd>
            </dl>
            <dl>
              <dt></dt>
              <dd><input name="btnSubmit" id="btnSubmit" type="submit" class="btn btn-success" value="确认发布" /></dd>
            </dl>
          </div>
        </form>
        <input id="turl" type="hidden" value="@bc.linkurl("usermessage","add")" />
      </div>
      <!--/发布短信息-->
      }
      
    </div>
    <!--/右侧内容-->
  </div>
</div>